﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace DotNetDI
{
    public class AppConfig: IAppConfig
    {
        public string this[string key]
        {
            get
            {
                if (!this.IsExist(key)) return null;
                return ConfigurationManager.AppSettings[key].ToString();
            }
        }

        public IDictionary<string, string> GetAllConfig()
        {
            IDictionary<string, string> allConfig = new Dictionary<string, string>();
            string[] allKeys = ConfigurationManager.AppSettings.AllKeys;
            foreach (var key in allKeys)
            {
                allConfig.Add(key, ConfigurationManager.AppSettings[key].ToString());
            }
            return allConfig;
        }

        public bool IsExist(string key)
        {
            string[] allKeys = ConfigurationManager.AppSettings.AllKeys;
            return allKeys.Contains(key);
        }
    }
}
